package com.czl.base.util

import android.annotation.SuppressLint
import java.text.SimpleDateFormat
import java.util.*

object DateHelper {

    fun computeEndDate(startDate: Date, num: Int): Date {
        val ca = Calendar.getInstance() // 得到一个Calendar的实例
        ca.time = startDate; // 设置时间为当前时间
        ca.add(Calendar.MONTH, +num) // 月份减1
        return ca.time // 结果
    }

    @SuppressLint("SimpleDateFormat")
    fun getNow(): String {
        return if (android.os.Build.VERSION.SDK_INT >= 24){
            SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())
        }else{
            val tms = Calendar.getInstance()
            tms.get(Calendar.YEAR).toString() + "-" + tms.get(Calendar.MONTH).toString() + "-" + tms.get(Calendar.DAY_OF_MONTH).toString() + " " + tms.get(Calendar.HOUR_OF_DAY).toString() + ":" + tms.get(Calendar.MINUTE).toString() +":" + tms.get(Calendar.SECOND).toString() +"." + tms.get(Calendar.MILLISECOND).toString()
        }

    }
}